package cm.android.mytodoit.controller.listeners;

import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
import cm.android.mytodoit.model.TodoElement;
import cm.android.mytodoit.view.DetailTodoview;

public class TodiListViewOnItemClickListener implements OnItemClickListener{
	
	private ListActivity listActivity;
	public TodiListViewOnItemClickListener(ListActivity listActivity){
		this.listActivity = listActivity;
	}


	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		
		TodoElement element = null;
		try {
			element = (TodoElement) listActivity.getListView().getAdapter().getItem(arg2);
			Intent intent = new Intent(listActivity, DetailTodoview.class);
			intent.putExtra(TodoElement.TC_ID, element.getId());
			listActivity.startActivity(intent);
		} catch (Exception e) {
			Toast.makeText(this.listActivity, "Failed", Toast.LENGTH_SHORT).show();
		
		}
				
	}

}
